package tw.asap.plus.ui.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import tw.asap.plus.R;
import tw.asap.plus.utils.ScreenUtil;

/**
 * Description:
 * Created:      [15/10/22]
 * Author:       [Yang]
 **/
public class CartButton extends FrameLayout {

    private TextView mTextView;
    private ImageView mImageView;

    public CartButton(Context context) {
        super(context);
    }

    public CartButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        mImageView = new ImageView(context);
        mImageView.setImageResource(R.drawable.main_cart_state_2);
        mImageView.setPadding(0,ScreenUtil.dip2px(context, 3),0,0);
        mTextView = new TextView(context);
        mTextView.setTextSize(10);
        mTextView.setText(R.string.cart_description);
        mTextView.setTextColor(getResources().getColor(R.color.palette_white));
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM ;
        params.setMargins(0, 0, 0, ScreenUtil.dip2px(context, 12));
        this.addView(mImageView);
        this.addView(mTextView, params);
    }

    public CartButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void switchState(int count){
        if(count == 0){
            mImageView.setImageResource(R.drawable.main_cart_state_2);
            mTextView.setVisibility(View.VISIBLE);
        }else {
            mImageView.setImageResource(R.drawable.main_cart_state_1);
            mTextView.setVisibility(View.INVISIBLE);
        }
    }
}
